import Vue from 'vue'
import Router from 'vue-router'
import Element from "element-ui"
import Login from "../views/Login"
import Main from "../views/Main"
import Notfound from "../views/Notfound"
import Tag02 from "../components/Tag02";
import Tag01 from "../components/Tag01";
import Tag03 from "../components/Tag03";
import Chat from "../components/Chat";
import Vuex from 'vuex';


Vue.use(Router)
Vue.use(Element)
Vue.use(Vuex)
const router=new Router({
  mode:"history",
  routes: [
    {
      path: '/',
      component: Login,
      show: true,
      meta:{
        title:'登录页',
        icon : 'el-icon-user',
      }
    },
    {
      path:"/main",
      component: Main,
      children:[{
        path:"/Tag02",
        component:Tag02,
        meta: {requireAuth: true}
      },
        {
        path:"/Tag01",
        component: Tag01,
        meta: {requireAuth: true}
        },
        {
        path:"/Tag03",
        component: Tag03,
        meta: {requireAuth: true}
        },
        {
          path:"/Chat",
          component: Chat,
          meta: {requireAuth: true}
        },
      ]
    },{
      path:"/*",
      component:Notfound
    }
  ]
})
export default router;
router.beforeEach((to, from, next) =>{
      //可以在路由元信息指定哪些页面需要登录权限
   const islogin=sessionStorage.getItem("islogin");
   // console.log(islogin);
   if(to.path==="/") {
     next()
    }
    else{
      if(!islogin){
       next('/Tag01')
      }
        next()
    }
})

